import numpy as np
from sklearn import datasets#数据集

iris=datasets.load_iris()#引入数据结
labels=np.copy(iris.target)
random_unlabeled_points=np.random.rand(len(iris.target))
random_unlabeled_points=random_unlabeled_points<0.3#小于0.3的返回1 大于0.3返回0
Y=labels[random_unlabeled_points]
print("Y:",Y)
labels[random_unlabeled_points]=-1
print("Unlabeled Number:",list(labels).count(-1))#无标注数据数量

from sklearn.semi_supervised import LabelPropagation#标签传播算法
label_prop_model=LabelPropagation()#建立对象
label_prop_model.fit(iris.data,labels)
Y_pred=label_prop_model.predict(iris.data)
Y_pred=Y_pred[random_unlabeled_points]
print("Y_pred:",Y_pred)
from sklearn.metrics import accuracy_score,recall_score,f1_score
print("ACC",accuracy_score(Y,Y_pred))
print("REC",recall_score(Y,Y_pred,average="micro"))
print("F-Score",f1_score(Y,Y_pred,average="micro"))


 
